#include "../../../common/channel.hpp"
#include "../../../common/etcd.hpp"
#include <gflags/gflags.h>
#include <brpc/server.h>
#include <butil/logging.h>
#include <thread>

DEFINE_bool(run_mode, false, "程序运行模式: false-调试; true 发布");
DEFINE_string(log_file, "", "发布模式下指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下指定日志的输出等级");

DEFINE_string(etcd_host, "http://127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");

void online(const std::string &service_name, const std::string &service_host){
    LOG_DEBUG("服务上线: {}-{}", service_name, service_host);
}
void offline(const std::string &service_name, const std::string &service_host){
    LOG_DEBUG("服务下线: {}-{}", service_name, service_host);
}

int main(int argc, char* argv[]){
    google::ParseCommandLineFlags(&argc, &argv, true);
    init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    Discovery::ptr rclient = std::make_shared<Discovery>(FLAGS_etcd_host, FLAGS_base_service, online, offline);
    
    // 1. 构造 rpc 信道管理对象
    // 2. 构造服务发现对象
    // 3. 提供 rpc 信道管理对象 获取提供 Echo 服务的信道
    // 4. 发起 EchoRpc 调用
    
    std::this_thread::sleep_for(std::chrono::seconds(600));
    return 0;
}

